\chapter{Music}

\section{Music Macro Language}

Music Macro Language (MML) has been used since the 1970s to sequence music on computer and video game systems. MML support is included in durexForth, starting with version 1.3. The package is loaded with \texttt{s" mml" load"}. Two demonstration songs can be found in the \texttt{mmldemo} package.

MML songs are played using the Forth word \texttt{play-mml} which takes three strings, one MML melody for each of the three SID voices. An example song is as follows:

\begin{verbatim}
: frere-jaques
s" o3l4fgaffgafab->c&c<ab->c&cl8cdc<b-l4af>l8cdc<b-l4affcf&ffcf&f"
s" r1o3l4fgaffgafab->c&c<ab->c&cl8cdc<b-l4af>l8cdc<b-l4affcf&ffcf&f"
s" " play-mml ;
\end{verbatim}

\section{Commands}

\begin{description}
\item[cdefgab] The letters \texttt{c} to \texttt{b} represent musical notes. Sharp notes are produced by appending a \texttt{+}, flat notes are produced by appending a \texttt{-}. The length of a note is specified by appending a number representing its length as a fraction of a whole note -- for example, \texttt{c8} represents a C eight note, and \texttt{f+2} an F\# half note. Valid note lengths are 1, 2, 3, 4, 6, 8, 16, 24 and 32. Appending a \texttt{.} increases the duration of the note by half of its value.
\item[o] Followed by a number, \texttt{o} selects the octave the instrument will play in.
\item[r] A rest. The length of the rest is specified in the same manner as the length of a note.
\item[$<$,$>$] Used to step down or up one octave.
\item[l] Followed by a number, specifies the default length used by notes or rests which do not explicitly specify one.
\item[\&] Ties two notes together.
\end{description}
